<?php
/**
 * 技师微信服务层
 */
namespace app\service;
class TechnWeixinService
{
	public static $mini_appid = 'wx74b59c9b284e7367'; //小程序appid
	public static $mini_appsecret = '7532b64368e1b0a3a8f98ad8a1da5135'; //小程序appsecret

	/**
	 * 获取微信小程序access_token
	 */
	public static function get_mini_access_token()
	{
		$wx_mini_access_token = cache('techn_wx_mini_access_token');
		if(!empty($wx_mini_access_token))
    	{
    		return $wx_mini_access_token;
    	}else
    	{
    		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".self::$mini_appid."&secret=".self::$mini_appsecret;
    		$res = http_curl($url);
    		$res = json_decode($res, true);
    		if(!empty($res['access_token']))
    		{
    			cache('techn_wx_mini_access_token', $res['access_token'], $res['expires_in']);
    			return $res['access_token'];
    		}
    	}
	}
}